package com.ttmusic.comparator;


import java.util.Comparator;

import com.ttmusic.entity.AbstractMusic;
import com.ttmusic.entity.MusicInfo;
import com.ttmusic.view.adapters.MusicAdapter;
import com.ttmusic.view.adapters.MusicAdapter.SortType;

/**
 * 音乐实体比较器-用于排序
 * @author wuchangyong
 * 
 */
public class MusicInfoComparator implements Comparator<AbstractMusic> {
    @Override
    public int compare(AbstractMusic lhs, AbstractMusic rhs) {
    	SortType type = MusicAdapter.getSortType();
    	int i = 0;
    	if(type == SortType.SORT_BY_ADDTIME) {
    		return -1;//添加时间还没获取到，要先做扫描，将歌曲信息保存到SQLite数据库中 增加一个添加时间字段
    	}else if(type == SortType.SORT_BY_ARTIST) {
    		i = lhs.getPinYinHeadCharofArtist().charAt(0) - rhs.getPinYinHeadCharofArtist().charAt(0);
    		return i;
    	}else if(type == SortType.SORT_BY_ALBUM) {
    		i = lhs.getPinYinHeadCharofAlbum().charAt(0) - rhs.getPinYinHeadCharofAlbum().charAt(0);
    		return i;
    	}
    	//默认按歌曲名称排序
    	i = lhs.getPinYinHeadCharofTitle().charAt(0) - rhs.getPinYinHeadCharofTitle().charAt(0);
		return i;
    }
}
